<?php
namespace Admin\Controller;
use Think\Controller;

class ArticleTypeController extends AdminCommonController {
	
    public function index(){
        $types = M('ArticleType') -> order('sort') -> select();
        $this->assign('types', $types);
        $this -> display();
    }
    
    public function addInput(){
        $this -> display();
    }
    public function add(){
        $rules = array(     
            array('name','require','请填写类型名称'),
        );
        $ArticleType = M('ArticleType');
        if (!$ArticleType->validate($rules)->create()){   
            $this->error($ArticleType->getError(),'',2);
        }else{
            $ArticleType -> add();
            $this -> success("添加成功！", "index");
        }
    }
    public function edit(){
        $id = I("get.id");
        $ArticleType = M('ArticleType');
        $data = $ArticleType -> find($id);
        $this -> assign("data",$data);
        $this -> display();
    }
    
    public function update(){
        $rules = array(     
            array('name','require','请填写类型名称'),
        );
        $ArticleType = M('ArticleType');
        if (!$ArticleType->validate($rules)->create()){   
            $this->error($Article->getError(),'',2);
        }else{
            $ArticleType -> save();
            $this -> success("修改成功！", "index");
        }
    }
    public function updateStatus(){
        $a_id = I("get.id");
        $ArticleType = M('ArticleType');
        $ArticleType -> find($a_id);
        if($ArticleType -> status == 0){
            $ArticleType -> status = 1;
        } else {
            $ArticleType -> status = 0;
        }
        $ArticleType -> save();
        $this -> success("状态修改成功");
    }
}
